<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>defineproperty</title>
</head>
<body>
    
    <script>
        
        /*
        
        var person = {};
        Object.defineProperty(person,"name",{
            writable:false,
            value:"zhangsan"
        });
        console.log(person);
        delete person.name;
        person.name = 'wangshuo';
        console.log(person);
        
        */

        var person = {
            _name: 'wangshuo',
            age: 27
        }

        Object.defineProperty(person,"name",{
            get () {
                return 'hello' + this._name;
            },
            set (val) {
                if (val.length === 9) {
                    this._name = val;
                    this.age = 2;
                }
            }
        })
        console.log(person.name);;
        person.name = 'wangzirui';

        console.log(person);

    </script>
</body>
</html>